<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>第三方链接</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../plugins/mui/mui.min.css" rel="stylesheet" />
		<script src="../../js/statistics.js"></script>
		<style>
			.header{
				background: #fff;
			}
			.header h1{
				color:#333;
				font-size:18px;	
			}
			.header a{
				color:#666;
			}
			.header .close{
				display: inline-block;
				width: 32px;
				height: 20px;
				margin: 13px 10px 9px 10px;
				font-size: 16px;
				color:#666;
				position: relative;
				z-index: 999999;
			}
			.header i{
				font-style: normal;
				font-size: 16px;
			}
		</style>
	</head>
	<body>
		<header class='mui-bar mui-bar-nav header mui-hidden'>
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"><i>返回</i></a>
			<span class="mui-pull-left close">关闭</span>
			<h1 id='title' class='mui-title'></h1>
		</header>
		<script src="../../plugins/mui/mui.min.js"></script>
		<script src='../../plugins/jquery/jquery-3.1.0.min.js'></script>
		<!--<script type="text/javascript" src="../../js/judge.js" ></script>-->
		<script src="../../js/getApiToken.js"></script>
		<script src="../../js/md5.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/sha1.js?version=1" ></script>
		<script type="text/javascript">
			mui.plusReady(function(){	
				var storage_array=
					[
						'life_cj','pay_hf','trave_fj'
					];
				//存储数据
				var self=plus.webview.currentWebview(),
					title=self.title,//标题
					life=self.life,//弹框信息
					isStorage=self.isStorage,//存储
					isTitle = self.isTitle || '', //是否为原生title页面
					Storage;
				mui("header").on('tap','.close',function(){
					self.close();
				});
				if(isTitle === ''){
					$('#title').html(title).parent().removeClass("mui-hidden");
				}
				for(var i=0;i<storage_array.length;i++){
					if(storage_array[i]==isStorage){
						if(isStorage == 'life_cj') {
							if(plus.storage.getItem(isStorage)=='true'){
								mui.alert("今日菜价里所有价格均为凌家塘批发价格，与市场价可能有差异，仅供参考，谢谢。",'温馨提示','我知道了',function(){
									Storage=plus.storage.setItem(isStorage,'false');
								});
							}
						}else{
							if(plus.storage.getItem(isStorage)=='true'){
								if(life){
									mui.alert("本服务由"+life+"提供，相关服务和责任将由该第三方承担。如有问题请咨询该公司客服。",'免责声明','我知道了',function(){
										Storage=plus.storage.setItem(isStorage,'false');
									});
								}else{
									mui.alert("本服务由三方提供，相关服务和责任将由该第三方承担。",'免责声明','我知道了',function(){
										Storage=plus.storage.setItem(isStorage,'false');
									});
								}	
							}
						}	
					}
				}
//				console.log(self.link)
//				console.log(self.isStorage);
				//判断是否为false
				var barItemWebviewArray;
				function inittabitemWebviews(){
					var agent = plus.storage.getItem('cg_agent');
					if(!self.link){
						return;
					}else if(self.isStorage == 'pay_df'){
						plus.navigator.setUserAgent(agent+'LYAPP');
						var uid = plus.storage.getItem('cg_user_id');
						var shaObj = new jsSHA("SHA-1", "TEXT");
						var time = new Date().getTime();
						var noncestr = hex_md5(time);
					    shaObj.update("noncestr="+noncestr+"&openid="+uid+"&special_field=LYAPP&timestamp="+time);
					    var hash = shaObj.getHash("HEX");
					   	var link ="https://weixin.js.sgcc.com.cn/wxapp_dlsh/mws/mwsMain_initMwsMain.do?openid="+uid+"&noncestr="+noncestr+"&timestamp="+time+"&sign="+hash;
						self.link = link;
						console.log(link);
					}else{
						plus.navigator.setUserAgent(agent);
					}
					barItemWebviewArray= mui.preload({
						id:self.link,
						url: self.link,
						styles:{
							top:'44px',
							bottom: '0',
							left: '0px',
							bounce: 'vertical',
						},
						waiting:{
							autoShow:true,//自动显示等待框，默认为true
							title:'正在加载...'//等待对话框上显示的提示内容
			      		}
					});
					self.append(barItemWebviewArray);
					barItemWebviewArray.show();	
					var back = function(){
			            self.close();
			        }
					//重写back事件，三方链接返回优化
			        mui.back = function(){
			        	plus.nativeUI.closeWaiting();
			            barItemWebviewArray.canBack(function(event){
			                var canBack = event.canBack;
			                if(canBack){
			                    barItemWebviewArray.back();
			                }else{
			                    back();
			                }
			            })
			
			        }
				}
				
				inittabitemWebviews();
			})
		</script>
	</body>
</html>